package com.sxyjhh.dbutil.utils;

import com.sxyjhh.dbutil.basic.ConstConfig;

/**
 * Description:数据库连接信息类
 *
 * @JDK Version:1.8.0_40
 * Version: V1.0
 * Author: wangchun
 * Date: 2016/3/30 14:22
 */
public class DBInfoUtil {


    public static String getDBUrl(ConstConfig.DBType dbType, String dbIP, String dbPort, String dbName){
        String dbUrlBase = null;
        switch (dbType){
            case MYSQL:
                dbUrlBase= DBConstConfig.DBUrlFormat.MYSQL_URL;
                break;
            case ORACLE:
                dbUrlBase= DBConstConfig.DBUrlFormat.ORACLE_URL;
                break;
            case SQLSERVER:
                dbUrlBase= DBConstConfig.DBUrlFormat.SQL_SERVER_URL;
                break;
            case DAMENG:
                dbUrlBase= DBConstConfig.DBUrlFormat.DM_URL;
                break;
            default:
                break;
        }
        if (dbUrlBase != null){
            return dbUrlBase.replace("{host}",dbIP).replace("{port}",dbPort).replace("{dbname}",dbName);
        }
        return null;
    }

    public static String getDBDriverName(ConstConfig.DBType dbType){
        switch (dbType){
            case MYSQL:
                return DBConstConfig.DBDriver.MYSQL_DRIVER;
            case ORACLE:
                return DBConstConfig.DBDriver.ORACLE_DRIVER;
            case SQLSERVER:
                return DBConstConfig.DBDriver.SQL_SERVER_DRIVER;
            case DAMENG:
                return DBConstConfig.DBDriver.DM_DRIVER;
            default:
                return null;
        }
    }


}
